export function isNotEmpty(str) {
    return str != undefined && str != null && str != ""
}

export function isEmpty(str) {
    return str == undefined || str == null || str == ''
}

export function formatDate(timestamp) {   //定义日期格式化函数
    if (isEmpty(timestamp)) return ""
    const date = new Date(parseInt(timestamp))
    let year = date.getFullYear();    //获取年份
    let month = date.getMonth() + 1;  //获取月份，从0开始计数，所以要加1
    let day = date.getDate();         //获取日期
    let hours = date.getHours()
    let minutes = date.getMinutes()
    let seconds = date.getSeconds()
    month = month < 10 ? '0' + month : month;   //如果月份小于10，前面补0
    day = day < 10 ? '0' + day : day;           //如果日期小于10，前面补0
    hours = hours < 10 ? '0' + hours : hours
    minutes = minutes < 10 ? '0' + minutes : minutes
    seconds = seconds < 10 ? '0' + seconds : seconds
    return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}

export function getYear(date) {
    if (date == null) date = new Date();

    return date.getFullYear()
}

export function getFullMonth(date) {
    if (date == null) date = new Date();
    let month = date.getMonth() + 1
    month = month < 10 ? '0' + month : month
    return date.getFullYear() + month
}

export function getLastFullMonth(date) {
    if (date == null) date = new Date();
    let month = date.getMonth() + 1
    if (month == 1) {
        month = 12
        return date.getFullYear() - 1 + month
    }
    month = month - 1
    month = month < 10 ? '0' + month : month
    return date.getFullYear() + month
}

export function getFullDay(date) {
    if (date == null) date = new Date();
    let month = date.getMonth() + 1
    let day = date.getDate()
    month = month < 10 ? '0' + month : month
    day = day < 10 ? '0' + day : day;
    return date.getFullYear() + month + day
}

export function formatMinuteToHour(minutes) {
    if (minutes == null) return 0;
    if (minutes < 60) return minutes + " 分钟";
    let hours = (minutes / 60).toString().split(".")[0];
    let hoursFormat = hours == 0 ? "" : hours + " 小时 ";
    minutes = minutes % 60;
    return hoursFormat +  " " +  minutes + " 分钟"
}


export function formatSecondsToMinuteHour(seconds) {
    if (seconds == null) return "";
    if (seconds < 60) return seconds + " 秒";

    let min_total = Math.floor(seconds / 60);
    let sec = Math.floor(seconds % 60)
    
    if (min_total < 60) {
        return min_total + " 分钟 " + sec + " 秒"
    }

    let hour_total = Math.floor(min_total / 60)
    let min = Math.floor(min_total % 60)
    return hour_total + " 小时 " + min + " 分钟 "  + sec + " 秒"
}